import os
import sys
from libavg import avg
from config import Config
from panels.controls import ControlPanel
from panels.wind import WindPanel
from board import Board
from panels.score import ScoreScreen
from panels.points import PointsBar

# the relative path to the sps folder

class Display(avg.DivNode):
    
    # display background
    background = None
    
    #panel with "new game", "pause/resume" and "language switch" options
    controlPanel = None
        
    #board for the first player (left board)
    boardLeft = None
    
    #board for the second player(right board)
    boardRight = None
    
    #panel showing wind direction and speed
    windPanel = None
    
    #bar at the bottom displaying current points 
    pointsBarLeft = None
    pointsBarRight = None  
    
    
    def __init__(self, size, parent):
        
        #divNode representing our display
        avg.DivNode.__init__(self, size=(Config.resX, Config.resY), parent=parent)
        #LOWEST LAYER: background
        self.background = avg.ImageNode(pos = (0,0), 
                    size = (Config.resX, Config.resY),
                    href = "../data/img/bg_720.png", parent=self)
    
        #display contents
       # self.controlPanel = ControlPanel(parent.size, self)     
        self.boardLeft = Board(parent.size, self,self.pointsBarLeft, True)        #1.Player
        self.boardRight = Board(parent.size, self,self.pointsBarRight,False)      #2.Player   
        
        #split line
        avg.LineNode(parent=self, 
                     pos1=(Config.resX/2, 0) , pos2=(Config.resX/2, Config.resY - Config.ctrlHeight), 
                     color="000000", strokewidth=2.5, opacity=0.5)
        
        #wind panel
        self.windPanel = WindPanel(parent.size, self)    

        #point bars
        self.pointsBarLeft = PointsBar(parent.size, self, True)
        self.pointsBarRight = PointsBar(parent.size, self, False)
        # points bar in wheels
        self.boardLeft.getWheel().setPointsbar(self.pointsBarLeft);
        self.boardRight.getWheel().setPointsbar(self.pointsBarRight);

    
    # end of game
    def gameOver(self):
        # simulator.pause()
        scoreScreen = ScoreScreen(self.pointsBarLeft, self.pointsBarRight)
        self.appendChild(scoreScreen)
